#include "doubly_linked_list.h"
#include <stdio.h>

void DoublyLinkedList(void)
{
    // 初始化双向链表
    DoublyNode_t *head = DoublyLinkedInit();

    // 插入3个节点
    BrowserData_t d1 = { "Github",  "2025-07-15 11:00", "https://github.com" };
    BrowserData_t d2 = { "Bilibili","2025-07-15 11:05", "https://www.bilibili.com" };
    BrowserData_t d3 = { "Zhihu",   "2025-07-15 11:10", "https://www.zhihu.com" };

    DoublyLinkedInsertToHead(head, &d1);
    DoublyLinkedInsertToTail(head, &d2);
    DoublyLinkedInsertCom(head, 2, &d3); // 插入到d1之后

    // 打印链表内容（正向遍历）
    printf("双向链表内容（正向遍历）:\n");
    DoublyNode_t *node = head->next;
    while (node) {
        printf("Title: %s, Time: %s, URL: %s\n",
               node->browserData.title,
               node->browserData.timestamp,
               node->browserData.url);
        node = node->next;
    }

    // 删除节点：按数据删除
    DoublyLinkedDeleteByIndex(head, 1);

    // 打印链表内容（再次正向）
    printf("\n删除Bilibili节点后的双向链表:\n");
    node = head->next;
    while (node) {
        printf("Title: %s, Time: %s, URL: %s\n",
               node->browserData.title,
               node->browserData.timestamp,
               node->browserData.url);
        node = node->next;
    }

    // 销毁链表
    DoublyLinkedDestroy(head);
}